<template>
  <div>
    <van-tabs @click="onClick">
      <van-tab title="全部">
        <img :src="imgs.img_url" alt="" v-for="imgs in images" :key="imgs.id" />
      </van-tab>
      <van-tab v-for="index in imglist" :title="index.title" :key="index.id">
        <img :src="imgs.img_url" v-for="imgs in images" :key="imgs.id" />
      </van-tab>
    </van-tabs>
  </div>
</template>

<script>
//  /api/getimages/:cateid
//  /api/getimgcategory
export default {
  name: 'imgCategory',
  data() {
    return {
      imglist: [],
      images: []
    }
  },
  methods: {
    async getimgcategory() {
      const res = await this.$http.getImgCategory()
      this.imglist = res.message;
    },
    async onClick(name) {
      const res = await this.$http.getCateImg(name)
      this.images = res.message;
    }
  },
  created() {
    this.$store.commit('changTiltle', '图片列表');
    this.getimgcategory();
    this.onClick(0);
  },
  beforeDestroy() {
    this.$store.commit('changTiltle', '首页');
  },

}

</script>
<style lang='scss'>
.van-tabs__content {
  img {
    width: 100%;
  }
}
</style>